<script setup>
import { ref ,onMounted} from 'vue';
import {pageApi} from '@/api/quality/text'
import {
  Search,
  Select,
  RefreshRight,
  Plus,
  Edit,
  Delete,
  View,
  CircleCheck,
  ShoppingCartFull,
  RefreshLeft,
} from '@element-plus/icons-vue'


// 搜索框
const search = ref({
  taskNumb:'',
  type:'',
  status:'',
  reason:'',
})
// 查询功能实现
const handleSearch = async()=>{
  let result = await pageApi(search.value.taskNumb,search.value.type,search.value.status,search.value.reason,currentPage.value,pageSize.value)
  tableData.value = result.data.rows
  total.value = result.data.total
}
// 清空实现
const clean = async() =>{
  search.value={
    taskNumb:'',
  type:'',
  status:'',
  reason:'',
  }
  handleSearch()
}
onMounted(()=>{
  handleSearch()
})

// 表格
const tableData = ref([])
// 分页配置
const currentPage = ref(1)
const pageSize = ref(10)
const total = ref(0)
const handleSizeChange =(val)=>{
  pageSize.value = val
  handleSearch()
}
const handleCurrentChange =(val)=>{
  currentPage.value = val
  handleSearch()
}

// 定义事件对象
const emits = defineEmits (['add','update','delete']) 
// 增加
const handleAdd = () =>{
  emits('add')
}
// 修改
const handleEdit = (row) =>{
  emits('update',row)
}
// 删除
const handleDelete = (id) =>{
  emits('delete',id)
}
// 暴露方法
defineExpose({
  handleSearch,
  tableData
})
</script>
<template>
 <!-- 搜索框 -->
  <el-form :model="search" label-width="auto" style="max-width: auto">
    <el-row :gutter="10">
      <el-col :span="5">
      <el-form-item label="任务单号">
        <el-input v-model="search.taskNumb" />
      </el-form-item>
      </el-col>

<el-col :span="5">
      <el-select v-model="search.type" placeholder="类型">
        <el-option label="首检" value="1" />
        <el-option label="巡检" value="2" />
        <el-option label="末检" value="3" />
      </el-select>
      </el-col>

    <el-col :span="5">
      <el-select v-model="search.status" placeholder="状态">
        <el-option label="未检验" value="1" />
        <el-option label="已检验" value="2" />
      </el-select>
      </el-col>

    <el-col :span="4">
      <el-select v-model="search.reason" placeholder="结果">
        <el-option label="NG" value="1" />
        <el-option label="OK" value="2" />
      </el-select>
      </el-col>

      <el-col :span="5">
  <el-tooltip content="搜索" placement="top">
    <el-button :icon="Search" type="success" @click="handleSearch" circle></el-button>
  </el-tooltip>
  <el-tooltip content="刷新" placement="top">
    <el-button :icon="RefreshRight" @click="clean" circle></el-button>
  </el-tooltip>
    <el-tooltip content="新增" placement="top">
    <el-button :icon="Plus" @click="handleAdd" circle></el-button>
  </el-tooltip>
  <br/><br/>
</el-col>
    </el-row>
  </el-form>
<!-- 表格 -->
 <el-table :data="tableData" style="width: 100%">
     <el-table-column label="序号" width="60">
      <template #default="scope">
        {{ (currentPage - 1) * pageSize + scope.$index + 1 }}
      </template>
    </el-table-column>
    <el-table-column prop="taskNumb" label="任务单号" width="180" />
    <el-table-column property="type" label="类型" width="200">
      <template #default="scope">
        <el-tag v-if="scope.row.status == 1">首检</el-tag>
        <el-tag v-else-if="scope.row.status == 2">巡检</el-tag>
        <el-tag v-else-if="scope.row.status == 3">3末检</el-tag>
      </template>
      </el-table-column>
    <el-table-column prop="workNub" label="工单号" />
    <el-table-column prop="sname" label="方案名" />
    <el-table-column property="status" label="状态" width="200">
      <template #default="scope">
        <el-tag v-if="scope.row.status == 1" type="danger">未检验</el-tag>
<el-tag v-else-if="scope.row.status == 2" type="success">已检验</el-tag>
      </template>
      </el-table-column>
    <el-table-column property="reason" label="结果" width="200">
      <template #default="scope">
        <el-tag v-if="scope.row.reason == 1" type="danger">NG</el-tag>
        <el-tag v-else-if="scope.row.reason == 2" type="success">OK</el-tag>
      </template>
      </el-table-column>
    <el-table-column prop="executor" label="执行人" width="200"/>
    <el-table-column prop="executeTime" label="执行时间" width="200"/>
    <el-table-column prop="name" label="权限角色" width="200"/>
    <el-table-column prop="createTime" label="创建时间" width="200"/>
    <el-table-column prop="createBy" label="创建人" width="200"/>
    <el-table-column prop="updateTime" label="修改时间" width="200"/>
 <el-table-column fixed="right" label="操作" min-width="120" width="200">
      <template #default="scope">
        <el-button link type="primary" @click="handleEdit(scope.row)" :icon="Edit" circle />
        <el-button link type="danger"  @click="handleDelete(scope.row)" :icon="Delete" circle />
      </template>
    </el-table-column>
  </el-table>
  <br>
<!-- 分页 -->
  <el-pagination
      v-model:current-page="currentPage"
      v-model:page-size="pageSize"
      :page-sizes="[10, 20, 30, 40]"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
</template>